﻿using System;   
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

using Alicanto.Helpers;
using Alicanto.Lexing;

namespace Alicanto.Compilation.Code.Blocks
{
    internal class Def : ICodeGenerator
    {
        public Expression Code { get; private set; }

        public Def()
        {
            this.Code = Expression.Empty();
        }

        public IEnumerable<ParseInstruction> Generate(TokenSequence tokens, Scope scope)
        {
            // Definition name
            string name = tokens.Pop(TokenType.SimpleName).Str;
            Type type = typeof(object);

            if (tokens.Peek() == Token.Colon)
            {
                tokens.Pop();
                tokens.Pop();
            }

            scope.ExecutionContext[name] = new Execution.ExecutionContextMember(null);
            yield break;
        }
    }
}
